﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Volo.Abp;
using Volo.Abp.Domain.Values;

namespace Mozhi.Abp.Domain.BasicData
{
    public class TaxRate : ValueObject
    {
        [JsonProperty]
        public Guid Id { get; protected set; }

        [JsonProperty]
        public string Name { get; protected set; }

        [JsonProperty]
        public string Code { get; protected set; }

        [JsonProperty]
        public bool Activated { protected set; get; }

        [JsonProperty]
        public decimal Rate { protected set; get; }

        public virtual decimal GetIncludeTaxValue(decimal value, bool includeTax)
        {
            if (value == 0)
                return 0;

            return includeTax ? value : value * (1 + Rate);
        }

        public virtual decimal GetExcludeTaxValue(decimal value, bool includeTax)
        {
            if (value == 0)
                return 0;

            return includeTax ? value / (1 + Rate) : value;
        }


        public virtual void Validate()
        {
            if (!Activated)
                throw new UserFriendlyException($"税率:{Code}-{Name}已禁用", "100000");
        }

        protected override IEnumerable<object> GetAtomicValues()
        {
            throw new NotImplementedException();
        }
    }
}
